function [pi0,R,T,K] = CalibrateCamera1( Xreal, xImg, PItru_ref )
xi = xImg;
Xi = Xreal;



%THIS IS NONSENSE!!! YOU NEED THE DEPTHS OF IMAGE POINTS FOR THIS !!!



% [xImg  xmean ymean scalef] = normalizeImgCoord(xImg);
% [Xreal  xmean3 ymean3 zmean3 scalef3] = normalize3DCoord(Xreal);


R = zeros(3,3);
T = zeros(3,1);
K = zeros(3,3);

N = size(xImg,2);
M = zeros(2 * N, 12);

for n = 1:2:2*N
   k = ceil(n/2);
   M(n,1:4) = -Xreal(1:4,k)';
   M(n,5:8) = zeros(1,4);
   M(n,9:12) =  xImg(1,k )*Xreal(1:4,k)';
   
   M(n+1,1:4) = zeros(1,4);
   M(n+1,5:8) = -Xreal(1:4,k)';
   M(n+1,9:12) = -xImg(2,k )*Xreal(1:4,k)';
    
end

[U,S,V] = svd(M); 
pi_star = V(:,12);

pi0 = reshape(pi_star,4,3)';

KR = pi0(1:3,1:3);
KT = pi0(1:3,4);

[K,R] = rq(KR);
T = K^-1 * KT;

breakhere =1 ;